Sampling data in different ways

37

#enumerate() function takes a collection/data (e.g. a tuple) and returns it as an enumerate object.
#This function adds a counter as the key of the enumerate object.
#In simple language enumerate will attach numbering starting from 0 to n- for the data provided.

x = ['Kushal', 'Aadarsh', 'Jay']  #[]
y = enumerate(x)  #,4

print(list(y)) #y      tuple   list
# Python program to illustrate 
# enumerate function in loops 
l1 = ["Johnwick","AD","Dead"] 

# printing the tuples in object directly 
for ele in enumerate(l1): 
	print (ele) 

print()

# changing index and printing separately 
for count,ele in enumerate(l1): 
	print (count,ele)

Comments

Submit
0 Comments